<template>
  <ul class="_m-2 p-2">
    <li class="border-bottom d-flex flex-wrap-wrap align-items-center">
      <span :class="[search.childSortId == '' ? 'active' : '']" @click="changeSortId('')">全部</span>
      <span
        :class="[search.childSortId == item.id ? 'active' : '']"
        v-for="item in sortList"
        :key="item.id"
        @click="changeSortId(item.id)"
      >{{item.sortName}}</span>
    </li>
    <li class="d-flex flex-wrap-wrap align-items-center">
      <span :class="[search.isOver == '' ? 'active' : '']" @click="changeIsOver('')">全部</span>
      <span
        :class="[search.isOver == isOver.Over ? 'active' : '']"
        @click="changeIsOver(isOver.Over)"
      >完结</span>
      <span
        :class="[search.isOver == isOver.No_Over ? 'active' : '']"
        @click="changeIsOver(isOver.No_Over)"
      >连载</span>
    </li>
  </ul>
</template>

<script>
import { config } from "assets/js/data";
import { getSortAllList } from "api/SortApi";

export default {
  name: "SearchBox",
  props: {
    searchData: Object
  },
  data() {
    return {
      search: {
        sortId: this.searchData.sortId,
        childSortId: this.searchData.childSortId,
        isOver: ""
      },
      isOver: config.isOver,
      sortList: []
    };
  },
  methods: {
    changeSortId(childSortId) {
      this.search.childSortId = childSortId;
      this.$emit("updateSearch", this.search);
    },
    changeIsOver(isOver) {
      this.search.isOver = isOver;
      this.$emit("updateSearch", this.search);
    },
    getSortAllList() {
      getSortAllList({
        parentId: this.search.sortId
      }).then(res => {
        this.sortList = res.data;
      });
    }
  },
  created() {
    this.getSortAllList();
  },
  watch: {
    sortId(newSortId) {
      this.search.sortId = newSortId;
      this.getSortAllList();
    }
  }
};
</script>

<style lang="stylus" scoped>
@import '~assets/css/style.styl';

ul {
  background: #FFF;

  li {
    font-size: 14px;
    margin-top: 2vw;
    margin-bottom: 2vw;
    padding: 0 0 1vw 0;

    span {
      padding: 1.3vw 0 1.5vw 0;
      flex: 0 0 19.2vw;

      &.active {
        color: $colorPrimary;
      }
    }
  }
}
</style>
